package com.whmskj.xjlhsc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.whmskj.xjlhbc.core.Page;
import com.whmskj.xjlhsc.controller.fo.GwjFo;
import com.whmskj.xjlhsc.controller.vo.DbcwVo;
import com.whmskj.xjlhsc.entity.CatalogueOfGy02Stations;
import com.whmskj.xjlhsc.entity.Sb02EquipmentCounterAccount;
import com.whmskj.xjlhsc.mapper.CatalogueOfGy02StationsMapper;
import com.whmskj.xjlhsc.service.GwjService;
import com.whmskj.xjlhsc.service.Sb02EquipmentCounterAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;


@Service
@Slf4j
public class GwjServiceImpl implements GwjService {


    @Autowired
    private Sb02EquipmentCounterAccountService sb02EquipmentCounterAccountService;

    @Autowired
    private CatalogueOfGy02StationsMapper catalogueOfGy02StationsMapper;

    @Override
    public List<Sb02EquipmentCounterAccount> gwjPb(GwjFo param) {
        Page.startPage();
        String process = param.getProcess();
        String jth = param.getJth();
        LambdaQueryWrapper<Sb02EquipmentCounterAccount> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.hasText(process), Sb02EquipmentCounterAccount::getProcess, process);
        wrapper.like(StringUtils.hasText(jth), Sb02EquipmentCounterAccount::getPlatform, jth);
        List<Sb02EquipmentCounterAccount> list = sb02EquipmentCounterAccountService.list(wrapper);
        list.forEach(item->{
            LambdaQueryWrapper<CatalogueOfGy02Stations> catalogueOfGy02StationsLambdaQueryWrapper = new LambdaQueryWrapper<>();
            catalogueOfGy02StationsLambdaQueryWrapper.eq(CatalogueOfGy02Stations::getProcess, item.getProcess());
            catalogueOfGy02StationsLambdaQueryWrapper.eq(CatalogueOfGy02Stations::getStationNumber, item.getPlatform()).last("limit 1");
            CatalogueOfGy02Stations catalogueOfGy02Stations = Optional.ofNullable(catalogueOfGy02StationsMapper.selectOne(catalogueOfGy02StationsLambdaQueryWrapper))
                    .orElseGet(CatalogueOfGy02Stations::new);
            item.setUserName("苏比努尔·卡哈买尔");
            item.setClasses("白班");
            item.setVariety(catalogueOfGy02Stations.getVarieties());
        });
        return list;
    }

    @Override
    public List<DbcwVo> gwjDbcw(GwjFo param) {
        List<DbcwVo> list = new ArrayList<>();
        for(int i=0;i<5;i++){
            DbcwVo vo = new DbcwVo();
            vo.setJtList(Arrays.asList("1#","2#","3#","4#","5#","6#","7#","8#","9#"));
            list.add(vo);
        }
        return list;
    }
}
